﻿using Microsoft.Extensions.Configuration;
namespace iTPS.Service.Core.Configurations
{
    using Resources;
    public class BasicSettingsConfigurationProvider : JsonSettingsConfigurationProvider
    {
        private IConfigurationRoot _environmentConfiguration;

        public string EnvironmentName { get; }

        public BasicSettingsConfigurationProvider()
        {
            _environmentConfiguration = new ConfigurationBuilder().AddEnvironmentVariables(prefix: "ASPNETCORE_").Build();



            EnvironmentName = _environmentConfiguration[ConstDefaults.EnvironmentNodeName];
            LoadJsonFile(EnvironmentName);

        }

        public ZeusSettingsConfiguration BuildZeusSettingsConfiguration()
        {
            var zeusJsonSettingsConfiguration = new ZeusSettingsConfiguration();
            ConfigurationRoot.Bind(zeusJsonSettingsConfiguration);
            return zeusJsonSettingsConfiguration;
        }

        public HttpClientUriConfiguration BuildHttpClientUriConfiguration()
        {
            var httpClientUriConfiguration = new HttpClientUriConfiguration();
            ConfigurationRoot.Bind(httpClientUriConfiguration);
            return httpClientUriConfiguration;
        }

        public DbConnectionSettingsConfiguration BuildDbConnectionConfiguration()
        {
            DbConnectionSettingsConfiguration dbConnectionSettingsConfiguration = new DbConnectionSettingsConfiguration();
            ConfigurationRoot.Bind(dbConnectionSettingsConfiguration);
            return dbConnectionSettingsConfiguration;
        }

        public RedisSettingsConfiguration BuildRedisSettingsConfiguration()
        {
            var redisSettingsConfiguration = new RedisSettingsConfiguration();
            ConfigurationRoot.Bind(redisSettingsConfiguration);
            return redisSettingsConfiguration;
        }

        public RabbitMqSettingsConfiguration BuildRabbitMqSettingsConfiguration()
        {
            var rabbitMqSettingsConfiguration = new RabbitMqSettingsConfiguration();
            ConfigurationRoot.Bind(rabbitMqSettingsConfiguration);
            return rabbitMqSettingsConfiguration;
        }

        public T Build<T>() where T : class, new()
        {
            var t = new T();
            ConfigurationRoot.Bind(t);
            return t;
        }
    }
}
